//
//  RegistedViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/9.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "RegistedViewController.h"
#import "HttpRequest.h"
#import "AddressView.h"
@interface RegistedViewController  ()<UITextFieldDelegate,UIGestureRecognizerDelegate ,UIScrollViewDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate>
@property(nonatomic,retain)NSString* agreement;
@property(nonatomic,retain)NSString*fid;
@end

@implementation RegistedViewController

{   UIScrollView*mainScroll;
    UIScrollView*mainScroll1;
    UITextField* userNameTextField;
    UITextField* passwordTextField;
    UITextField* phoneTextField;
    UITextField* paypasswordTextField;
    UITextField* verificationCode;
    UIButton* ToObtain;
    BOOL saveAccount;
    UIView* view1;
    UIView* view2;
    UIButton* agreementBtn;
    MBProgressHUD *progressHud;
    UIView*myToolBar;
    UIButton* registdd;
    UIButton* agreementBtnBig;
    NSMutableArray* DataLine;
    AddressView*Addressview;
    UILabel* GPRS;
}
@synthesize alt = alt;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"用户注册";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     backColor,
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    
    
    
    // 手势
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [self.view addGestureRecognizer:singleFingerOne];
    mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];

    [mainScroll setBackgroundColor:[UIColor colorWithRed:255/255.00 green:255/255.00 blue:255/255.00 alpha:1.0]];
    mainScroll.delegate = self;
    mainScroll.userInteractionEnabled = YES;
    mainScroll.scrollEnabled = YES;

    UILabel *line0 = [[UILabel alloc]initWithFrame:CGRectMake(10,188/2, ScreenWidth-20, 0.45)];
    line0.backgroundColor = qianhuiColor;
    [mainScroll addSubview:line0];
    UILabel *line1 = [[UILabel alloc]initWithFrame:CGRectMake(10,340/2, ScreenWidth-20, 0.45)];
    line1.backgroundColor = qianhuiColor;
    [mainScroll addSubview:line1];
    UILabel *line3 = [[UILabel alloc]initWithFrame:CGRectMake(10,428/2, ScreenWidth-20, 0.45)];
    line3.backgroundColor = qianhuiColor;
    [mainScroll addSubview:line3];
    
    
    
    
    phoneTextField = [[UITextField alloc] initWithFrame:CGRectMake(20,  100/2, ScreenWidth-35, 44)];
    [phoneTextField setBorderStyle:   UITextBorderStyleNone]; //外框类型
    phoneTextField.placeholder = @"请输入手机号码"; //默认显示的字
    phoneTextField.font = [UIFont systemFontOfSize: 14];
    phoneTextField.returnKeyType = UIReturnKeyDone;
    phoneTextField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    phoneTextField.delegate = self;
    phoneTextField.keyboardType = UIKeyboardTypeDecimalPad;
    [phoneTextField addTarget:self action:@selector(userNumberLimitTextLength:) forControlEvents:UIControlEventEditingChanged];
    [mainScroll addSubview:phoneTextField];
    
    myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(closeKeyBoad) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:keyboardFot];
    [btnDone111 addTarget:self action:@selector(closeKeyBoad) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(closeKeyBoad) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    
    phoneTextField.inputAccessoryView = myToolBar;
    passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 188/2, ScreenWidth-35, 44)];
    [passwordTextField setBorderStyle:   UITextBorderStyleNone]; //外框类型
    passwordTextField.placeholder = @"请输入登录密码"; //默认显示的字    passwordTextField.secureTextEntry = YES; //
    passwordTextField.font = [UIFont systemFontOfSize: 14];
    passwordTextField.secureTextEntry = YES; //密码
    passwordTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    passwordTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    passwordTextField.returnKeyType = UIReturnKeyDone;
    passwordTextField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    passwordTextField.delegate = self;
    passwordTextField.tag=5;
    [mainScroll addSubview:passwordTextField];
    passwordTextField.inputAccessoryView = myToolBar;
    
    UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(10,276/2, ScreenWidth-20, 0.5)];
    _xianview.image=[UIImage imageNamed:@"hengxian"];
    [mainScroll addSubview:_xianview];
    UILabel* label=[[UILabel alloc]initWithFrame:CGRectMake(80, 295/2, ScreenWidth-100, 12)];
    label.text=@"密码由6-20位英文字母或数字组成";
    label.textAlignment=NSTextAlignmentRight;
    [label setTextColor:[UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1.0]];
    label.font = [UIFont systemFontOfSize:12];
    NSMutableAttributedString *AttributedSt = [[NSMutableAttributedString alloc]initWithString:@"密码由6-20位英文字母或数字组成"];
    
    [AttributedSt addAttribute:NSFontAttributeName
     
                         value:[UIFont systemFontOfSize:12]
     
                         range:NSMakeRange(3, 4)];
    
    [AttributedSt addAttribute:NSForegroundColorAttributeName
     
                         value:zhonghuiColor
     
                         range:NSMakeRange(3, 4)];
    
    
    label.attributedText = AttributedSt;
    [mainScroll addSubview:label];

    verificationCode = [[UITextField alloc] initWithFrame:CGRectMake(20, 340/2, 190, 44)];
    [verificationCode setBorderStyle:UITextBorderStyleNone]; //外框类型
    verificationCode.placeholder = @"请输入手机验证码"; //默认显示的
    verificationCode.font = [UIFont systemFontOfSize: 14];
    verificationCode.autocorrectionType = UITextAutocorrectionTypeNo;
    verificationCode.autocapitalizationType = UITextAutocapitalizationTypeNone;
    verificationCode.returnKeyType = UIReturnKeyDone;
    verificationCode.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    verificationCode.delegate = self;
    verificationCode.tag=5;
    verificationCode.keyboardType = UIKeyboardTypeDecimalPad;
    [mainScroll addSubview:verificationCode];
    verificationCode.inputAccessoryView = myToolBar;
    ToObtain = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-90-15, line1.bottom+7.5, 90,30)];
    [ToObtain setTitle:@"获取验证码" forState:UIControlStateNormal];
    ToObtain.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    [ToObtain.layer setCornerRadius:1.0]; //设置矩圆角半径
    [ToObtain.layer setBorderWidth:0.5];   //边框宽度
    CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){228/255.0, 228/255.0, 228/255.0, 1.0});
    [ToObtain.layer setBorderColor:tureBTncolorref];//边框颜色
    [ToObtain setTitleColor:[UIColor colorWithRed:249/255.0 green:53/255.0 blue:30/255.0 alpha:1.0]
 forState:UIControlStateNormal];
    [ToObtain addTarget:self action:@selector(startTime) forControlEvents:UIControlEventTouchUpInside];
    [mainScroll addSubview:ToObtain];
    
    
    
    agreementBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, line3.bottom+18, 16, 16.0)];
    [agreementBtn.layer setCornerRadius:1.0]; //设置矩圆角半径
    [agreementBtn.layer setBorderWidth:0.5];   //边框宽度
    CGColorSpaceRef tureBTnSpace3 = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref3 = CGColorCreate(tureBTnSpace3,(CGFloat[]){204/255.0, 204/255.0, 204/255.0, 1.0});
    [agreementBtn.layer setBorderColor:tureBTncolorref3];//边框颜色
    [agreementBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
    [mainScroll addSubview:agreementBtn];
    
    agreementBtnBig = [[UIButton alloc] initWithFrame:CGRectMake(10, 460/2, 40, 40)];
    [agreementBtnBig addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
    [mainScroll addSubview:agreementBtnBig];
    
    UILabel* agreedLabel=[[UILabel alloc]initWithFrame:CGRectMake(43,line3.bottom+20, 28,13)];
    agreedLabel.text=@"同意";
    [agreedLabel setTextColor:zhonghuiColor];
    agreedLabel.font = [UIFont systemFontOfSize:13];
    [mainScroll addSubview:agreedLabel];
    
    UIButton* agreementBtnLabel = [[UIButton alloc] initWithFrame:CGRectMake(agreedLabel.right,line3.bottom+20, 180, 13)];
    NSString *str1=[NSString stringWithFormat:@"%d",TARGET_VERSION];
    if ([str1 isEqualToString:@"4"]) {
        
     [agreementBtnLabel setTitle:@"《卓越星辰服务协议》" forState:UIControlStateNormal];
   
    }else if([str1 isEqualToString:@"1"]||[str1 isEqualToString:@"11"]) {
               
        [agreementBtnLabel setTitle:@"《体验购服务协议》" forState:UIControlStateNormal];
    
    }else if([str1 isEqualToString:@"6"]||[str1 isEqualToString:@"16"]) {
        
        [agreementBtnLabel setTitle:@"《保宝云服务协议》" forState:UIControlStateNormal];
        
    }

    
    
    
    agreementBtnLabel.titleLabel.font = [UIFont systemFontOfSize: 13];
    [agreementBtnLabel setTitleColor:luseColor forState:UIControlStateNormal];
    agreementBtnLabel.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [agreementBtnLabel addTarget:self action:@selector(agreementBtnLabel:) forControlEvents:UIControlEventTouchUpInside];
    [mainScroll addSubview:agreementBtnLabel];
    
    
    registdd = [[UIButton alloc] initWithFrame:CGRectMake(10, 540/2, ScreenWidth-20, anniuHeigth)];
    [registdd setTitle:@"立即注册" forState:UIControlStateNormal];
    [registdd setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [registdd.layer setCornerRadius:2.0]; //设置矩圆角半径
    [registdd.layer setBorderWidth:0.3];   //边框宽度
    CGColorSpaceRef tureBTnSpace44 = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref44 = CGColorCreate(tureBTnSpace44,(CGFloat[]){204.0/255.0, 204.0/255.0, 204.0/255.0, 1.0});
    [registdd.layer setBorderColor:tureBTncolorref44];//边框颜色
    registdd.backgroundColor=qianhuiColor;
    [mainScroll addSubview:registdd];
    
    [mainScroll setContentSize:CGSizeMake(ScreenWidth, ScreenHeight+50)];
    [self.view addSubview:mainScroll];
}

-(void)registdd:(UIButton*)sender{
    
    if ([phoneTextField.text length]<1)
    {
        [self showAlertMessage:@"请输入手机号码"];
   
    }else if ([verificationCode.text length]<1)
    {
        [self showAlertMessage:@"请输入验证码"];
    }
    else if ([passwordTextField.text length]<1)
    {
        [self showAlertMessage:@"请输入密码"];
    }
    
    else if (![self.agreement isEqualToString:@"ty" ]) {
        [self showAlertMessage:@"需要同意服务协议！"];
    }

}
-(void)agreementBtnLabel:(UIButton*)sender{
    
//    xieyiViewController* Login=[[xieyiViewController alloc]init];
//    [self.navigationController pushViewController:Login animated:YES];
    
}

-(void)chooseBtn:(id)sender
{
    
    if ([phoneTextField.text length]<1)
    {
        [self showAlertMessage:@"请输入手机号码"];
    
    }else if ([verificationCode.text length]<1)
    {
        [self showAlertMessage:@"请输入验证码"];
    }
    else if ([passwordTextField.text length]<1)
    {
        [self showAlertMessage:@"请输入密码"];
    }
    
    else {
        saveAccount=!saveAccount;
        if (saveAccount) {
                agreementBtn. backgroundColor=luseColor;

            self.agreement=@"ty";
            
            [registdd removeFromSuperview];
            registdd = [[UIButton alloc] initWithFrame:CGRectMake(15,540/2, ScreenWidth-30, anniuHeigth)];
            [registdd setTitle:@"立即注册" forState:UIControlStateNormal];
            [registdd setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            registdd.backgroundColor=luseColor;
            [registdd.layer setCornerRadius:3.0]; //设置矩圆角半径
            [registdd.layer setBorderWidth:0.3];   //边框宽度
            CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
            CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){23/255.0,148/255.0, 153/255.0, 1.0});
            [registdd.layer setBorderColor:tureBTncolorref];//边框颜色
            [registdd addTarget:self action:@selector(regist:) forControlEvents:UIControlEventTouchUpInside];
            [mainScroll addSubview:registdd];
            
            
        }
        else
        {
             agreementBtn. backgroundColor=nil;
//            [agreementBtn setImage:[UIImage imageNamed:@"_0000_weigouxuan.png"] forState:UIControlStateNormal];
            self.agreement=@"bty";
            [registdd removeFromSuperview];
            registdd = [[UIButton alloc] initWithFrame:CGRectMake(15, 540/2, ScreenWidth-30, anniuHeigth)];
            [registdd setTitle:@"立即注册" forState:UIControlStateNormal];
            
            [registdd setTitleColor:qianhuiColor forState:UIControlStateNormal];
            [registdd.layer setCornerRadius:3.0]; //设置矩圆角半径
            [registdd.layer setBorderWidth:0.5];   //边框宽度
            CGColorSpaceRef loginBTnSpace = CGColorSpaceCreateDeviceRGB();
            CGColorRef loginBTncolorref = CGColorCreate(loginBTnSpace,(CGFloat[]){204.0/255.0, 204.0/255.0, 204.0/255.0, 1.0});
            [registdd.layer setBorderColor:loginBTncolorref];//边框颜色
            [mainScroll addSubview:registdd];
            }
    }
}

//号码限制
- (void)userNumberLimitTextLength:(UITextField*)textField
{
    if ([textField.text length] >= 11)
    {
        textField.text = [textField.text substringToIndex:11];
 
    }
}
- (void)paypasswordTextField:(UITextField*)textField
{
    if ([textField.text length] > 20)
    {
        //        NSRange range=NSMakeRange(6,20);
        //        textField.text = [textField.text substringFromIndex:];
    }
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    
    if (textField.tag == 5)
    {
        
        if (range.location >= 12)
            return NO;}
    if (textField.tag == 6)
    {
        if (range.location>=12)
            return NO;}
    return YES;
}




- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
    [textField resignFirstResponder];
    
    
    return YES;
}

-(void)startTime{
    
    if ([phoneTextField.text length]<1)
    {
        [self showAlertMessage:@"请输入手机号码"];
    }else{
        if ([phoneTextField.text length]!=11)
        {
            [self showAlertMessage:@"手机位数有误"];
        }else{
            
            __block int timeout=60; //倒计时时间
            dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
            dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
            dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
            dispatch_source_set_event_handler(_timer, ^{
                if(timeout<=0){ //倒计时结束，关闭
                    dispatch_source_cancel(_timer);
                    dispatch_async(dispatch_get_main_queue(), ^{
                        //设置界面的按钮显示 根据自己需求设置
                        
                        
                        
                        
                        [ToObtain setTitle:@"获取" forState:UIControlStateNormal];
                        ToObtain.userInteractionEnabled = YES;
                    });
                }else{
                    //            int minutes = timeout / 60;
                    int seconds = timeout % 60;
                    NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        //设置界面的按钮显示 根据自己需求设置
                        //                NSLog(@"____%@",strTime);
                        if (strTime.intValue==59) {
                            NSLog(@"____%@",strTime);
                            NSMutableDictionary *params = [NSMutableDictionary new];
                            [params setValue:phoneTextField.text forKey:@"mobile"];
                            [params setValue:@"A" forKey:@"msgType"];
                           [HttpRequest requestData1:@"Common/SendMsg" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                                if (isSuccess) {
                                    NSLog(@"====%@",severDataDict.dataDict);
                                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                                        [Global hideProgressHUDInternal:self.view];
                                         NSString*ResultString=[severDataDict.dataDict objectForKey:@"ResultString"];
                                       [self showAlertMessage:ResultString];
                                        
                                    }else{
                                        [Global hideProgressHUDInternal:self.view];
                                    }}
                                else
                                {
                                    [Global hideProgressHUDInternal:self.view];
                                    [Global showTextHudSub:severDataDict.resultStr view:self.view];
                                }
                            }];
                        }
                        
                        if (![strTime isEqualToString:@"00"]) {
                            [ToObtain setTitle:[NSString stringWithFormat:@"%@秒重获",strTime] forState:UIControlStateNormal];
                            
                        }
                        ToObtain.userInteractionEnabled = NO;
                        
                    });
                    timeout--;
                    
                }
            });
            dispatch_resume(_timer);
        }}}
-(void)regist:(UIButton*)sender{
    
    
    if ([phoneTextField.text length]<1)
    {
        [self showAlertMessage:@"请输入手机号码"];
   
    }else if ([verificationCode.text length]<1)
    {
        [self showAlertMessage:@"请输入验证码"];
    }
    else if ([passwordTextField.text length]<1)
    {
        [self showAlertMessage:@"请输入密码"];
    }
    
    else if (![self.agreement isEqualToString:@"ty" ]) {
        [self showAlertMessage:@"需要同意服务协议"];
    }
    
    else{
        
        [Global showIndeterminateHud:@"注册中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params = [NSMutableDictionary new];
        
        [params setValue:phoneTextField.text forKey:@"mobile"];
        [params setValue:[MyMD5 md5:passwordTextField.text] forKey:@"loginWord"];
        [params setValue:verificationCode.text forKey:@"msgCode"];
        [params setValue:@"A" forKey:@"msgType"];
        [params setValue:self.fid forKey:@"fid"];
        [HttpRequest requestData1:@"Common/Register" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                NSLog(@"====%@",severDataDict.dataDict);
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    NSString*UserName=phoneTextField.text;
                    NSString*Password=passwordTextField.text;
                    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                    [user setObject:UserName forKey:@"userNameTextField"];
                    [user setObject:Password forKey:@"passwordTextField"];
             
                    [user synchronize];
                    [self.navigationController popViewControllerAnimated:YES];
              
                }else{
                    [Global hideProgressHUDInternal:self.view];
                    [self showAlertMessage:[severDataDict.dataDict objectForKey:@"ResultString"]];
                    }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:severDataDict.resultStr view:self.view];
            }
        }];
    
    }}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    if (textField.tag == 5)
    {
        
          }
    else if (textField.tag == 6)
    {
        
        
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        mainScroll .frame =CGRectMake(0, -50, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
        
    }
}

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定哦 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}


- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:2.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)closeKeyBoad{
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    mainScroll .frame =CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    [paypasswordTextField resignFirstResponder];
    [phoneTextField resignFirstResponder];
    [userNameTextField resignFirstResponder];
    [passwordTextField resignFirstResponder];
    [verificationCode resignFirstResponder];

}

@end
